This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
Allow decoding while debugging Yul sources in Solidity 0.8.21 (and related changes) #6154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows decoding of variables while decoding Yul sources that were compiled with solc 0.8.21 or greater. Note this PR does not address #3831, I figured that was better saved for later.
It was already possible to decode Yul variables in Solidity
assembly
blocks, but not in straight Yul files, because Solidity wouldn't give us ASTs for the latter. But now it does!Well, now it does if we ask for them right. For some reason, Solidity makes us ask for the ast at the contract level when compiling Yul, instead of at the file level like normal; I've filed an issue about that (although for 0.8.21 compatibility we'll have to leave this extra bit in anyway). Also, there's another bug regarding these (which I've also filed an issue about) -- it assigns the singular source an ID of 1 instead of 0. So, I had to add in a workaround for that as well.
Once we have the ASTs, the debugger can do the rest, so not many more changes were needed! But there are two.
First off, it turns out that the top-level node in a Yul AST, the
YulObject
node type, doesn't have ansrc
field. So the code in Codec that gets the source index from the top node of an AST needed some adjustment in that case. Not only does theYulObject
node lack this info, but so does theYulCode
node below it; one has to go to theYulBlock
node atast.code.block
to get it. Fortunately these nodes are always present -- I tried. (Of course we could also just always return 0, but hey, if the info is there let's use it, right? :P )Second off, since an AST might now have
YulObject
rather thanSourceUnit
as its top-level node, a bunch of code in data that assumed thatSourceUnit
is the only type of top-level node has been updated to account forYulObject
as well. Some of this got factored out intohelpers
.Finally, I added a test! One caveat -- the test did not work right once I introduced mutation. O_o I assume this is due to something with the optimizer or something? I decided to just omit that from the test, which is not great, but I didn't see what else I could reasonably do.
Note that adding this test obviously involved increasing the Solidity version used in the debugger tests to 0.8.21, and for some reason that slowed down a few tests, so I increased the timeout on those few.
I also tested this manually using the
yul-test
project in the solidity-test-cases repo.